package com.hooware.controller;

import com.hooware.domain.Permission;
import com.hooware.service.IPermissionService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/findAll.do")
    public String findAll(Model model) {
        List<Permission> permissionList = permissionService.findAll();
        model.addAttribute("permissionList",permissionList);
        System.out.println("============查询所有权限信息===========" + permissionList);
        return "permission-list";
    }

    @RequestMapping("/save.do")
    public String save(Permission permission) {
        permissionService.savePermission(permission);
        System.out.println("============查询所有权限信息===========" + permission);
        return "redirect:findAll.do";
    }

    @RequestMapping("/deletePermission.do")
    public String deletePermission(String id) {
        permissionService.deletePermission(id);
        System.out.println("============删除角色信息=========== id = " + id);
        return "redirect:findAll.do";
    }

    @RequestMapping("/findById.do")
    public String findById(Model model,String id) {
        Permission permission = permissionService.findById(id);
        model.addAttribute("permission",permission);
        System.out.println("============根据id查询权限信息===========" + permission);
        return "permission-show";
    }
}
